# Maintainer: Wu Zhenyu <wuzy01@qq.com>

_realname=fd
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=10.2.0
pkgrel=1
pkgdesc='Simple, fast and user-friendly alternative to find (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/sharkdp/fd'
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
license=('spdx:Apache-2.0 OR MIT')
msys2_references=(
  'archlinux: fd'
  'purl: pkg:cargo/fd-find'
)
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha512sums=('db7a41d0dd448d73a88f7920b0d67d5d99864fef0a7d64a91523a55af9fd745e6520df8aee808f4131a07acd34730571d94a20e1e6aa1336c6f3caaab593d4ab')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  make prefix="${MINGW_PREFIX}"
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  make install DESTDIR="${pkgdir}" prefix="${MINGW_PREFIX}"

  install -Dm644 LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/fd/"
}
